class Admin::NavigaBarsController < Admin::ApplicationController
  before_action :set_naviga_bar, only: [:show, :edit, :update, :destroy]

  # GET /admin/naviga_bars
  def index
    @naviga_bars = NavigaBar.where(admin_user_id: current_admin_user_id, company_id: current_company_id).page(params[:page]).per(10)
  end

  # GET /admin/naviga_bars/1
  def show
  end

  # GET /admin/naviga_bars/new
  def new
    @naviga_bar = NavigaBar.new
  end

  # GET /admin/naviga_bars/1/edit
  def edit
  end

  # POST /admin/naviga_bars
  def create
    @naviga_bar = NavigaBar.new(naviga_bar_params.merge({admin_user_id: current_admin_user_id, company_id: current_company_id}))

    if @naviga_bar.save
      redirect_to admin_naviga_bars_url, notice: '保存成功'
    else
      render :new
    end
  end

  # PATCH/PUT /admin/naviga_bars/1
  def update
    if @naviga_bar.update(naviga_bar_params)
      redirect_to admin_naviga_bars_url, notice: '保存成功'
    else
      render :edit
    end
  end

  # DELETE /admin/naviga_bars/1
  def destroy
    @naviga_bar.destroy
    redirect_to admin_naviga_bars_url, notice: '删除成功'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_naviga_bar
      @naviga_bar = NavigaBar.find_by(id: params[:id], company_id: current_company_id)
    end

    # Only allow a trusted parameter "white list" through.
    def naviga_bar_params
      params.require(:naviga_bar).permit(:key, :name, :order_number)
    end
end
